package com.dream52.pms.util;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;


/**
 * 字符串处理类
 */
public class StringUtil {
    static final int MAXSPACES = 2560;
    static final int MAXZEROS = 2560;
    static final int DEFAULTDECIMALS = 6;
    static final int EXPONENTLEN = 3;
    static int SPACESLEN = 40;
    static int ZEROSLEN = 40;
    static String SPACES = "                                        ";
    static String ZEROS = "0000000000000000000000000000000000000000";
    static Object lock = new Object();

    /**
     * 构造方法
     */
    public StringUtil() {
    }


    /**
     * 替换换行符
     *
     * */
    public static String replaceN(String myString){
        //newString = myString.replaceAll("(\r\n|\r|\n|\n\r)", "");
        return "aaaa";
    }

    /**
     * 在字符串中查找指定的字符串,并返回
     *
     * @param fieldname
     *            现有字符串
     * @param key
     *            要查找的字符串
     * @return 转换成查找数据库的格式，如 like '% %'
     */
    public static String getSearchString(String fieldname, String key) {
        if (key == null || key.length() <= 0) {
            return "";
        }
        String key1 = key + "&", char1 = "", returnStr = "", key2 = "", oldchar = "";
        int oldpos = 0;
        for (int i = 0; i < key1.length(); i++) {
            char1 = key1.substring(i, i + 1);
            if (char1.equalsIgnoreCase(" ") || char1.equalsIgnoreCase("*")
                    || char1.equalsIgnoreCase("+")
                    || char1.equalsIgnoreCase("&")
                    || char1.equalsIgnoreCase("-")
                    || char1.equalsIgnoreCase("|")) {
                key2 = key2 + key1.substring(oldpos, i);
                if (oldpos == 0) {
                    key2 = key2 + "&";
                } else {
                    key2 = key2 + oldchar;
                }
                oldchar = char1;
                oldpos = i + 1;
            }
        }
        key1 = key2;
        oldpos = 0;
        for (int i = 0; i < key1.length(); i++) {
            char1 = key1.substring(i, i + 1);
            if (char1.equalsIgnoreCase(" ") || char1.equalsIgnoreCase("*")
                    || char1.equalsIgnoreCase("+")
                    || char1.equalsIgnoreCase("&")) {
                if (key1.substring(oldpos, i).length() > 0) {
                    returnStr += " and (" + fieldname + " like '%"
                            + key1.substring(oldpos, i) + "%')";
                }
                oldpos = i + 1;
                continue;
            }
            if (char1.equalsIgnoreCase("|")) {
                if (key1.substring(oldpos, i).length() > 0) {
                    returnStr += " or (" + fieldname + " like '%"
                            + key1.substring(oldpos, i) + "%')";
                }
                oldpos = i + 1;
                continue;
            }
            if (char1.equalsIgnoreCase("-")) {
                if (key1.substring(oldpos, i).length() > 0) {
                    returnStr += " and ( " + fieldname + " not like '%"
                            + key1.substring(oldpos, i) + "%')";
                }
                oldpos = i + 1;
                continue;
            }
        }
        return returnStr;
    }

    /**
     * 判断一个字符串是否属于一个有逗号分隔的字符串
     * */
    public static boolean isIn(String s,String ss,String c){
        boolean rst=false;

        String tmp[] = split(ss,c);
        for(int i=0;i<tmp.length;i++)
        {
            if(s.indexOf(c)>0)
            {
                String tmps[] = split(s,c);
                for(int j=0;j<tmps.length;j++)
                {
                    if(tmps[j].equals(tmp[i]))
                    {
                        rst = true;
                        break;
                    }
                }
            }
            else
            {
                if(s.equals(tmp[i]))
                {
                    rst = true;
                    break;
                }
            }
        }

        return rst;
    }

    /**
     * 获得一个随机数
     *
     * @param maxvalue
     *            最大数
     * @return 随机数
     */
    private static int getRandomNumberA(int maxvalue) {
        return NumberUtil.getRandomNumber(maxvalue);
    }

    private static String getRandomStrA(int Number, String StringList) {
        String rst = "";
        for (int i = 0; i < Number; i++) {
            int random = getRandomNumberA(StringList.length() * 3);
            random = random % StringList.length();
            rst = rst + StringList.charAt(random);
        }
        return rst;
    }

    /**
     * 参数Number作为位数，获得数字随机数
     *
     * @param Number
     *            随机数位数
     * @return 随机数
     */
    public static String getRandomStrNumber(int Number) {
        return getRandomStrA(Number, "0123456789");
    }

    /**
     * 参数Number作为位数，获得随机字母
     *
     * @param Number
     *            位数
     * @return 随机字母
     */
    public static String getRandomStrAlpha(int Number) {
        return getRandomStrA(Number,
                "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
    }

    /**
     * 参数Number作为位数，获得随机混合字符串
     *
     * @param Number
     *            位数
     * @return 随机混合字符串
     */
    public static String getRandomString(int Number) {
        return getRandomStrA(Number,
                "01234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
    }

    /**
     * 从01234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ中选取字符
     * 传入的参数是字符所在的位置，例如：
     * 传入2则返回2；
     * 传入11，返回a
     * @param Number
     *            字符所在的位置 int 类型
     * @return 单个字符串
     */
    public static String getSingleString(int Number) {
        String rst = "01234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
        return "" + rst.charAt(Number);
    }

    /**
     * 获得字符串"\n"
     *
     * @return "\n"
     */
    public static String getReturn() {
        return "\n";
    }

    /**
     * 获得len个空格
     *
     * @param len
     *            空格个数
     * @return len个空格
     */
    public static String getSpaces(int len) {
        if (len > SPACESLEN && SPACESLEN < 2560) {
            synchronized (lock) {
                for (; len > SPACESLEN && SPACESLEN < 2560; SPACESLEN += SPACESLEN)
                    SPACES = String.valueOf(SPACES) + String.valueOf(SPACES);
            }
        }
        return SPACES.substring(0, len);
    }

    /**
     * 获得下一个值
     *
     * @param curNo
     *            当前值
     * @param leng
     *            curNo的长度
     * @return 下一个值
     */
    public static String getNextNo(String curNo, int leng) {
        int curleng = leng;
        int strlen = curNo.length();
        if (curleng > strlen)
            curleng = strlen;
        long nextValue = Long.parseLong(curNo.substring(strlen - leng)) + 1;
        String tail = "" + nextValue;
        for (int i = 0; i < leng; i++)
            tail = "0" + tail;
        curNo = curNo.substring(0, strlen - leng)
                + tail.substring(tail.length() - leng);
        return curNo;
    }

    /**
     * 判断该名称是否图片或文件
     *
     * @param field
     *            完整路径
     * @return 如果是图片或文件，返回true;否则返回falses
     */
    public static boolean likePicOrFile(String field) {
        String newfield = field.toLowerCase();
        if (newfield.endsWith("pic") || newfield.endsWith("path")
                || newfield.endsWith("file"))
            return true;
        else
            return false;
    }

    /**
     * 获得len个零
     *
     * @param len
     *            len个零
     * @return len个零
     */
    public static String getZeros(int len) {
        if (len > ZEROSLEN && ZEROSLEN < 2560) {
            synchronized (lock) {
                for (; len > ZEROSLEN && ZEROSLEN < 2560; ZEROSLEN += ZEROSLEN)
                    ZEROS = String.valueOf(ZEROS) + String.valueOf(ZEROS);
            }
        }
        return ZEROS.substring(0, len);
    }

    /**
     * 获得字符串，用空格向左填充len大于s的长度。如s="322",len=4，则返回" "322
     *
     * @param s
     *            需填充的字符串
     * @param len
     *            长度
     * @return 字符串
     */
    public static String padLeft(String s, int len) {
        return padLeft(s, len, false);
    }

    /**
     * 获得字符串，当s的长度大于len时，用空格填充len大于s的长度。否则就截取。如s="322",len=4，则返回" "322
     * s="3232",len=,则返回323。如果不用截取就使用方法padLeft(String s, int len)
     *
     * @param s
     *            源字符串
     * @param len
     *            长度
     * @param trim
     *            是否要截取
     * @return 字符串
     */
    public static String padLeft(String s, int len, boolean trim) {
        int slen = s.length();
        String ret;
        if (slen < len)
            ret = String.valueOf(getSpaces(len - slen)) + String.valueOf(s);
        else {
            if (slen > len && trim)
                ret = s.substring(0, len);
            else
                ret = s;
        }
        return ret;
    }

    /**
     * 获得字符串，用空格向右填充len大于s的长度。如s="322",len=4，则返回322" "
     *
     * @param s
     *            源字符串
     * @param len
     *            长度
     * @return 字符串
     */
    public static String padRight(String s, int len) {
        return padRight(s, len, false);
    }

    /**
     * 获得字符串，当s的长度大于len时，用空格填充len大于s的长度。否则就截取。如s="322",len=4，则返回322" "
     * s="3232",len=,则返回232。如果不用截取就使用方法padRight(String s, int len)
     *
     * @param s
     *            源字符串
     * @param len
     *            长度
     * @param trim
     *            是否要截取
     * @return 字符串
     */
    public static String padRight(String s, int len, boolean trim) {
        int slen = s.length();
        String ret;
        if (slen < len)
            ret = String.valueOf(s) + String.valueOf(getSpaces(len - slen));
        else {
            if (slen > len && trim)
                ret = s.substring(0, len);
            else
                ret = s;
        }
        return ret;
    }

    /**
     * 获取左填充0字符串
     *
     * @param s
     *            源字符串
     * @param len
     *            长度
     * @return 填充后的字符串
     */
    public static String padZero(String s, int len) {
        int slen = s.length();
        String ret;
        if (slen < len)
            ret = String.valueOf(getZeros(len - slen)) + String.valueOf(s);
        else
            ret = s;
        return ret;
    }

    /**
     * 获取左填充0字符串
     *
     * @param value
     *            源数字
     * @param len
     *            长度
     * @return 填充后的字符串
     */
    public static String padZero(int value, int len) {
        String s = "".concat(String.valueOf(String.valueOf(value)));
        int slen = s.length();
        String ret;
        if (slen < len)
            ret = String.valueOf(getZeros(len - slen)) + String.valueOf(s);
        else
            ret = s;
        return ret;
    }

    /**
     * 按格式转换
     *
     * @param format
     *            格式
     * @param value
     *            转换值
     * @return 转换后的字符串
     */
    public static String getFormatted(String format, int value) {
        FormatParas fp = new FormatParas();
        parseFormatString(format, fp);
        String ret = fp.prefix.toString();
        System.out.println(fp.specfound);
        if (fp.specfound) {
            String valstring;
            if (fp.basetype == 'i')
                valstring = toString(value, fp);
            else {
                if (fp.basetype == 'f')
                    valstring = toString(value, fp);
                else {
                    if (fp.basetype == 'c')
                        valstring = toString((char) value, fp);
                    else
                        valstring = "<***cannot convert value***>";
                }
            }
            ret = String.valueOf(ret)
                    + String.valueOf(String.valueOf(valstring)
                    + String.valueOf(fp.suffix.toString()));
        }
        return ret;
    }

    /**
     * 按格式转换
     *
     * @param format
     *            格式
     * @param value
     *            转换值
     * @return 转换后的字符串
     */
    public static String getFormatted(String format, double value) {
        FormatParas fp = new FormatParas();
        parseFormatString(format, fp);
        String ret = fp.prefix.toString();
        if (fp.specfound) {
            String valstring;
            if (fp.basetype == 'f')
                valstring = toString(value, fp);
            else {
                if (fp.basetype == 'i')
                    valstring = toString((int) value, fp);
                else
                    valstring = "<***cannot convert value***>";
            }
            ret = String.valueOf(ret)
                    + String.valueOf(String.valueOf(valstring)
                    + String.valueOf(fp.suffix.toString()));
        }
        return ret;
    }

    /**
     * 字符串连接
     *
     * @param source1
     *            第一个值
     * @param source2
     *            最后一个值
     * @param midstr
     *            中间值
     * @return 连接后的字符串
     */
    public static String getCombineNoNullString(String source1, String source2,
                                                String midstr) {
        if (source1 == null || source1.length() > 0)
            return "";
        if (source2 == null || source2.length() > 0)
            return "";
        return source1 + midstr + source2;
    }

    /**
     * 按格式转换
     *
     * @param format
     *            格式
     * @param value
     *            转换值
     * @return 转换后的字符串
     */
    public static String getFormatted(String format, char value) {
        FormatParas fp = new FormatParas();
        parseFormatString(format, fp);
        String ret = fp.prefix.toString();
        if (fp.specfound) {
            String valstring;
            if (fp.basetype == 'c')
                valstring = toString(value, fp);
            else {
                if (fp.basetype == 's')
                    valstring = toString("".concat(String.valueOf(String
                            .valueOf(value))), fp);
                else {
                    if (fp.basetype == 'i')
                        valstring = toString(value, fp);
                    else
                        valstring = "<***cannot convert value***>";
                }
            }
            ret = String.valueOf(ret)
                    + String.valueOf(String.valueOf(valstring)
                    + String.valueOf(fp.suffix.toString()));
        }
        return ret;
    }

    /**
     * 按格式转换
     *
     * @param format
     *            格式
     * @param value
     *            转换值
     * @return 转换后的字符串
     */
    public static String getFormatted(String format, String value) {
        FormatParas fp = new FormatParas();
        parseFormatString(format, fp);
        String ret = fp.prefix.toString();
        if (fp.specfound) {
            String valstring;
            if (fp.basetype == 's') {
                valstring = toString(value, fp);
            } else {
                valstring = "<***cannot convert value***>";
            }
            ret = String.valueOf(ret)
                    + String.valueOf(String.valueOf(valstring)
                    + String.valueOf(fp.suffix.toString()));
        }
        return ret;
    }

    /**
     * 测试格式转换
     *
     * @param format
     *            格式
     * @return 转换后的字符串
     */
    public static String testFormatParser(String format) {
        FormatParas fp = new FormatParas();
        parseFormatString(format, fp);
        return String.valueOf(String.valueOf((new StringBuffer(
                "\nFormat String....: ")).append(format).append("\n").append(
                fp.toString())));
    }

    /**
     * 把FormatParas对象转换成字符对象
     *
     * @param value
     *            值
     * @param fp
     *            FormatParas对象
     * @return 转换后的字符串
     */
    private static String toString(int value, FormatParas fp) {
        String ret = "";
        int signlen = 0;
        char sign = ' ';
        if (fp.convchar == 'd' || fp.convchar == 'u') {
            if (fp.convchar == 'u') {
                value = Math.abs(value);
            }
            if (value < 0) {
                ret = "".concat(String.valueOf(String.valueOf(-value)));
                signlen = 1;
                sign = '-';
            } else {
                ret = "".concat(String.valueOf(String.valueOf(value)));
                if (fp.plussign) {
                    signlen = 1;
                    sign = '+';
                }
            }
            if (fp.decimals > 0) {
                ret = String.valueOf(ret)
                        + String.valueOf(".".concat(String.valueOf(String
                        .valueOf(getZeros(fp.decimals)))));
            }
        } else if (fp.convchar == 'x') {
            ret = Integer.toHexString(value);
        } else if (fp.convchar == 'X') {
            ret = Integer.toHexString(value).toUpperCase();
        } else if (fp.convchar == 'o') {
            ret = Integer.toOctalString(value);
        }
        if (fp.fieldlen > 0) {
            if (fp.padzero) {
                ret = padZero(ret, fp.fieldlen - signlen);
                if (signlen > 0) {
                    ret = String.valueOf(sign) + String.valueOf(ret);
                }
            } else {
                if (signlen > 0) {
                    ret = String.valueOf(sign) + String.valueOf(ret);
                }
                if (fp.alignleft) {
                    ret = padRight(ret, fp.fieldlen);
                } else {
                    ret = padLeft(ret, fp.fieldlen);
                }
            }
        } else if (signlen > 0) {
            ret = String.valueOf(sign) + String.valueOf(ret);
        }
        return ret;
    }

    private static String toString(double value, FormatParas fp) {
        String ret = "";
        char convchar = fp.convchar;
        int signlen = 0;
        char sign = ' ';
        if (value < (double) 0) {
            signlen = 1;
            sign = '-';
            value = -value;
        } else if (fp.plussign) {
            signlen = 1;
            sign = '+';
        }
        if (fp.convchar == 'g' || fp.convchar == 'G') {
            if (value >= 1000D || value < 0.001D) {
                convchar = fp.convchar != 'g' ? 'E' : 'e';
            } else {
                convchar = 'f';
            }
        }
        int exp;
        String canonical;
        if (value == 0.0D) {
            exp = 0;
            canonical = "0.0";
        } else {
            exp = (int) (Math.floor(Math.log(value) / Math.log(10D)) + (double) 1);
            double normalized = value / Math.pow(10D, exp);
            if (normalized >= 1.0D) {
                exp = (int) ((double) exp + 1.0D);
                normalized = value / Math.pow(10D, exp);
            }
            if (normalized < 0.10000000000000001D) {
                exp = (int) ((double) exp - 1.0D);
                normalized = value / Math.pow(10D, exp);
            }
            canonical = "".concat(String.valueOf(String.valueOf(normalized)));
        }
        if (!canonical.startsWith("0.")) {
            ret = "***unexpected canonical form: ".concat(String.valueOf(String
                    .valueOf(ret)));
        } else {
            canonical = canonical.substring(2);
            String s1;
            String s2;
            String s3;
            if (convchar == 'f') {
                if (exp > 0) {
                    s1 = (String.valueOf(canonical) + String
                            .valueOf(getZeros(exp))).substring(0, exp);
                    s2 = (String.valueOf(canonical) + String
                            .valueOf(getZeros(exp))).substring(exp);
                } else if (exp < 0) {
                    s1 = "0";
                    s2 = String.valueOf(getZeros(-exp))
                            + String.valueOf(canonical);
                } else {
                    s1 = "0";
                    s2 = canonical;
                }
                s3 = "";
            } else {
                s1 = "0";
                s2 = canonical;
                if (exp >= 0) {
                    s3 = String.valueOf(String.valueOf((new StringBuffer(""))
                            .append(convchar).append("+").append(
                                    padZero(exp, 3))));
                } else {
                    s3 = String.valueOf(String.valueOf((new StringBuffer(""))
                            .append(convchar).append("-").append(
                                    padZero(-exp, 3))));
                }
            }
            int decimals = fp.decimals != -1 ? fp.decimals : 6;
            if (decimals == 0) {
                if (s2.charAt(0) >= '5') {
                    s1 = incrementString(s1);
                }
                s2 = "";
            } else {
                s2 = String.valueOf(s2)
                        + String.valueOf(getZeros(decimals + 1));
                if (s2.charAt(decimals) >= '5') {
                    s2 = incrementString(s2.substring(0, decimals));
                    if (s2.length() > decimals) {
                        if (convchar == 'f') {
                            s2 = s2.substring(1);
                            s1 = incrementString(s1);
                        } else {
                            s2 = "1".concat(String.valueOf(String.valueOf(s2
                                    .substring(2))));
                            int newexp = exp + 1;
                            if (newexp >= 0) {
                                s3 = String.valueOf(String
                                        .valueOf((new StringBuffer("")).append(
                                                convchar).append("+").append(
                                                padZero(newexp, 3))));
                            } else {
                                s3 = String.valueOf(String
                                        .valueOf((new StringBuffer("")).append(
                                                convchar).append("-").append(
                                                padZero(-newexp, 3))));
                            }
                        }
                    }
                } else {
                    s2 = s2.substring(0, decimals);
                }
            }
            ret = String.valueOf(String.valueOf((new StringBuffer(String
                    .valueOf(String.valueOf(s1)))).append(
                    decimals <= 0 ? "" : ".".concat(String.valueOf(String
                            .valueOf(s2)))).append(s3)));
            if (fp.fieldlen > 0) {
                if (fp.padzero) {
                    ret = padZero(ret, fp.fieldlen - signlen);
                    if (signlen > 0) {
                        ret = String.valueOf(sign) + String.valueOf(ret);
                    }
                } else {
                    if (signlen > 0) {
                        ret = String.valueOf(sign) + String.valueOf(ret);
                    }
                    if (fp.alignleft) {
                        ret = padRight(ret, fp.fieldlen);
                    } else {
                        ret = padLeft(ret, fp.fieldlen);
                    }
                }
            } else if (signlen > 0) {
                ret = String.valueOf(sign) + String.valueOf(ret);
            }
        }
        return ret;
    }

    private static String toString(char value, FormatParas fp) {
        String ret = "".concat(String.valueOf(String.valueOf(value)));
        if (fp.fieldlen > 0) {
            if (fp.alignleft) {
                ret = padRight(ret, fp.fieldlen);
            } else {
                ret = padLeft(ret, fp.fieldlen);
            }
        }
        return ret;
    }

    private static String toString(String value, FormatParas fp) {
        if (fp.fieldlen > 0) {
            if (fp.alignleft) {
                value = padRight(value, fp.fieldlen);
            } else {
                value = padLeft(value, fp.fieldlen);
            }
        }
        return value;
    }

    private static void parseFormatString(String format, FormatParas fp) {
        int specpos = 0;
        for (int formatlen = format.length(); formatlen > 0;) {
            specpos = format.indexOf("%");
            if (specpos == -1 || specpos >= formatlen - 1) {
                if (!fp.specfound) {
                    fp.prefix.append(format);
                } else {
                    fp.suffix.append(format);
                }
                format = "";
                formatlen = 0;
            } else if (format.charAt(specpos + 1) == '%') {
                if (!fp.specfound) {
                    fp.prefix.append(format.substring(0, specpos + 1));
                } else {
                    fp.suffix.append(format.substring(0, specpos + 1));
                }
                format = format.substring(specpos + 2);
                formatlen -= specpos + 2;
            } else if (fp.specfound) {
                fp.suffix.append(format.substring(0, specpos + 1));
                format = format.substring(specpos + 1);
                formatlen -= specpos + 1;
            } else {
                fp.prefix.append(format.substring(0, specpos));
                format = format.substring(specpos + 1);
                formatlen -= specpos + 1;
                fp.specfound = true;
                int i = 0;
                int numpos = 0;
                int num[] = { -1, -1 };
                boolean firstdigit = true;
                for (; i < formatlen; i++) {
                    char c = format.charAt(i);
                    if (c == '-') {
                        fp.alignleft = true;
                        continue;
                    }
                    if (c == '+') {
                        fp.plussign = true;
                        continue;
                    }
                    if (c == 'l' || c == 'L') {
                        fp.aslong = true;
                        continue;
                    }
                    if (c >= '0' && c <= '9') {
                        if (num[numpos] == -1) {
                            num[numpos] = 0;
                        }
                        num[numpos] = (10 * num[numpos] + c) - 48;
                        if (c == '0' && firstdigit) {
                            fp.padzero = true;
                        }
                        firstdigit = false;
                        continue;
                    }
                    if (c == '.') {
                        numpos = 1;
                        continue;
                    }
                    if ("dxXou".indexOf(c) != -1) {
                        fp.convchar = c;
                        fp.basetype = 'i';
                        i++;
                        break;
                    }
                    if ("feEgG".indexOf(c) != -1) {
                        fp.convchar = c;
                        fp.basetype = 'f';
                        i++;
                        break;
                    }
                    if (c == 'c') {
                        fp.convchar = c;
                        fp.basetype = 'c';
                        i++;
                        break;
                    }
                    if (c == 's') {
                        fp.convchar = c;
                        fp.basetype = 's';
                        i++;
                    } else {
                        i++;
                    }
                    break;
                }

                fp.fieldlen = num[0];
                fp.decimals = num[1];
                format = format.substring(i);
                formatlen -= i;
            }
        }
    }

    private static String incrementString(String s) {
        StringBuffer sb = new StringBuffer(s);
        int i = sb.length() - 1;
        do {
            if (i < 0) {
                break;
            }
            char c = sb.charAt(i);
            if (c < '9') {
                sb.setCharAt(i, (char) (c + 1));
                break;
            }
            sb.setCharAt(i, '0');
            i--;
        } while (true);
        return String.valueOf(i != -1 ? "" : "1")
                + String.valueOf(sb.toString());
    }

    /**
     * 格式化输出
     *
     * @param sFormat
     *            格式
     * @param obj
     *            字符串数组
     * @return 字符串
     */
    public static String format(String sFormat, String obj[]) {
        int len = obj.length;
        String sResult = sFormat;
        for (int i = 0; i < len; i++) {
            sResult = getFormatted(sResult, obj[i]);

        }
        return sResult;
    }

    /**
     * 字符串替换
     *
     * @param src
     *            源字符串
     * @param sFnd
     *            被替换字符串
     * @param sRep
     *            替换的字符串
     * @return 替换后的字符串
     */
    public static String replaceStr(String src, String sFnd, String sRep) {
        String sTemp = "";
        int endIndex = 0;
        int beginIndex = 0;
        if (src == null || sFnd == null)
            return src;
        do {
            endIndex = src.indexOf(sFnd, beginIndex);
            if (endIndex >= 0) {
                sTemp = String.valueOf(sTemp)
                        + String.valueOf(String.valueOf(src.substring(
                        beginIndex, endIndex))
                        + String.valueOf(sRep));
                beginIndex = endIndex + sFnd.length();
                continue;
            }
            if (beginIndex < 0) {
                continue;
            }
            sTemp = String.valueOf(sTemp)
                    + String.valueOf(src.substring(beginIndex));
            break;
        } while (endIndex >= 0);
        return sTemp;
    }

    //把!$-#@._/,\"替换成\u4E21\u4EB9\u4E85\u4EC8\u4ED0\u4E0F\u4E35\u4E6B\u4E06\u4E6D
    /**
     * 根据规则替换字符串
     *
     * @param str
     *            源字符串
     * @return 替换后的字符串
     */
    public static String chgHkigo2Zkigo(String str) {
        String tmp = "";
        String Z_kigo = "\u4E21\u4EB9\u4E85\u4EC8\u4ED0\u4E0F\u4E35\u4E6B\u4E06\u4E6D";
        String H_kigo = "!$-#@._/,\"";
        tmp = str;
        for (int i = 0; i < H_kigo.length(); i++) {
            tmp = tmp.replace(H_kigo.charAt(i), Z_kigo.charAt(i));

        }
        return tmp;
    }

    // 替换字符串，
    // 把源字符串中的\u50C8\u50CA\u50CC\u50CE\u50D1\u50D3\u50D5\u50D8\u50DB\u50DD\u50DF\u50E1\u50E4\u50E8\u50EA\u50F6\u50F9\u50FD\u5100\u5103\u50F7\u50FA\u50FE\u5101\u5104
    // 替换成
    // \u6387\u5FFF\u768B\u7F50\u6068\u6666\u5AC1\u776B\u5DE8\u54ED\u64C2\u8D41\u7F57\u68C9\u9713\u517D\u5BBF\u5254\u5A03\u65E0\u852C\u8BC9\u8E22\u74E6\u829C
    // 再把
    // \u8F88\u7092\u5200\u72AF\u8D2D\u60A3\u9A84\u5777\u8C05\u5A9A\u724C\u4FA8\u5892\u9882\u81C0\u95F2\u5CA9\u91C9\u7F69\u68D5\u4EDD\u572E
    // \uE731
    // 替换成
    // \u50BE\u50C0\u50C2\u50C4\u50C6\u50C7\u50C9\u50CB\u50CD\u50D0\u50D2\u50D4\u50D7\u50D9\u50DC\u50DE\u50E0\u50E3\u50E5\u50E9\u50EB\u50EF\u50F0\u50F1\u50F2\u50F4\u50F8\u50FC\u50FF\u5102\u5105\u5108\u5109\u510A\u510C\u510E\u5110\u5113\u5114\u5115\u5116\u5117\u5118\u511A\u511D\u511E
    /**
     * 按规则替换字符串
     *
     * @param str
     *            需要替换的源字符串
     * @return 替换后的字符串
     */
    public static String chgHkana2Zkana(String str) {
        String Z_kana = "\u50BE\u50C0\u50C2\u50C4\u50C6\u50C7\u50C9\u50CB\u50CD\u50D0\u50D2\u50D4\u50D7\u50D9\u50DC\u50DE\u50E0\u50E3\u50E5\u50E9\u50EB\u50EF\u50F0\u50F1\u50F2\u50F4\u50F8\u50FC\u50FF\u5102\u5105\u5108\u5109\u510A\u510C\u510E\u5110\u5113\u5114\u5115\u5116\u5117\u5118\u511A\u511D\u511E";
        String H_kana = "\u8F88\u7092\u5200\u72AF\u8D2D\u60A3\u9A84\u5777\u8C05\u5A9A\u724C\u4FA8\u5892\u9882\u81C0\u95F2\u5CA9\u91C9\u7F69\u68D5\u4EDD\u572E\uE731";
        String Z_kana2 = "\u6387\u5FFF\u768B\u7F50\u6068\u6666\u5AC1\u776B\u5DE8\u54ED\u64C2\u8D41\u7F57\u68C9\u9713\u517D\u5BBF\u5254\u5A03\u65E0\u852C\u8BC9\u8E22\u74E6\u829C";
        String H_kana2 = "\u50C8\u50CA\u50CC\u50CE\u50D1\u50D3\u50D5\u50D8\u50DB\u50DD\u50DF\u50E1\u50E4\u50E8\u50EA\u50F6\u50F9\u50FD\u5100\u5103\u50F7\u50FA\u50FE\u5101\u5104";
        String tmp = str;
        for (int i = 0; i < H_kana2.length(); i++) {
            tmp = tmp.replace(H_kana2.charAt(i), Z_kana2.charAt(i));

        }
        for (int i = 0; i < H_kana.length(); i++) {
            tmp = tmp.replace(H_kana.charAt(i), Z_kana.charAt(i));

        }
        return tmp;
    }

    /**
     * 替换\r\n，\r，\n，\b
     *
     * @param str
     *            源字符串
     * @return 替换后的字符串
     */
    public static String chgCRLFTAB2SPC(String str) {
        String tmp = str;
        tmp = replaceStr(tmp, "\r\n", " ");
        tmp = replaceStr(tmp, "\r", " ");
        tmp = replaceStr(tmp, "\n", " ");
        tmp = replaceStr(tmp, "\b", " ");
        return tmp;
    }

    /**
     * 是否有kana
     *
     * @param str
     *            源字符串
     * @return 有返回true,否则为false
     */
    public static boolean hasKana(String str) {
        String kana = "\u50BE\u50C0\u50C2\u50C4\u50C6\u50C7\u50C9\u50CB\u50CD\u50D0\u50D2\u50D4\u50D7\u50D9\u50DC\u50DE\u50E0\u50E3\u50E5\u50E9\u50EB\u50EF\u50F0\u50F1\u50F2\u50F4\u50F8\u50FC\u50FF\u5102\u5105\u5108\u5109\u510A\u510C\u510E\u5110\u5113\u5114\u5115\u5116\u5117\u5118\u511A\u511D\u511E";
        kana = String
                .valueOf(String.valueOf(kana))
                .concat(
                        "\u50C8\u50CA\u50CC\u50CE\u50D1\u50D3\u50D5\u50D8\u50DB\u50DD\u50DF\u50E1\u50E4\u50E8\u50EA\u50F6\u50F9\u50FD\u5100\u5103\u50F7\u50FA\u50FE\u5101\u5104\u50BD\u50BF\u50C1\u50C3\u50C5\u5120\u5122\u50E2\u510D\u510F\u5111\u5119");
        kana = String
                .valueOf(String.valueOf(kana))
                .concat(
                        "\u5041\u5044\u5046\u504A\u504D\u5050\u5052\u5054\u5057\u5059\u505D\u505F\u5061\u5063\u5066\u5068\u506A\u506E\u5070\u5072\u5074\u5075\u5078\u5079\u507A\u507C\u5082\u5086\u508A\u508E\u5091\u5092\u5093\u5094\u5095\u5097\u5099\u509B\u509C\u509D\u509E\u509F\u50A0\u50A2\u50AA\u50AB");
        kana = String
                .valueOf(String.valueOf(kana))
                .concat(
                        "\u5051\u5053\u5056\u5058\u505B\u505E\u5060\u5062\u5064\u5067\u5069\u506B\u506F\u5071\u5073\u507D\u5083\u5087\u508B\u508F\u5081\u5084\u5089\u508C\u5090\u5040\u5042\u5045\u5049\u504B\u506D\u5096\u5098\u509A\u50A1\u4E55");
        kana = String
                .valueOf(String.valueOf(kana))
                .concat(
                        "\u8F88\u7092\u5200\u72AF\u8D2D\u60A3\u9A84\u5777\u8C05\u5A9A\u724C\u4FA8\u5892\u9882\u81C0\u95F2\u5CA9\u91C9\u7F69\u68D5\u4EDD\u572E\uE731\u0416\u2506\uE06C\uE0C8\uE1B5\u7519");
        for (int i = 0; i < str.length(); i++) {
            if (kana.indexOf(str.substring(i, i + 1)) >= 0) {
                return true;
            }
        }

        return false;
    }

    /**
     * 判断kana
     *
     * @param str
     *            源字符串
     * @return 正确为true,否则为false
     */
    public static boolean chkKana(String str) {
        String kana = "\u50BE\u50C0\u50C2\u50C4\u50C6\u50C7\u50C9\u50CB\u50CD\u50D0\u50D2\u50D4\u50D7\u50D9\u50DC\u50DE\u50E0\u50E3\u50E5\u50E9\u50EB\u50EF\u50F0\u50F1\u50F2\u50F4\u50F8\u50FC\u50FF\u5102\u5105\u5108\u5109\u510A\u510C\u510E\u5110\u5113\u5114\u5115\u5116\u5117\u5118\u511A\u511D\u511E";
        kana = String
                .valueOf(String.valueOf(kana))
                .concat(
                        "\u50C8\u50CA\u50CC\u50CE\u50D1\u50D3\u50D5\u50D8\u50DB\u50DD\u50DF\u50E1\u50E4\u50E8\u50EA\u50F6\u50F9\u50FD\u5100\u5103\u50F7\u50FA\u50FE\u5101\u5104\u50BD\u50BF\u50C1\u50C3\u50C5\u5120\u5122\u50E2\u510D\u510F\u5111\u5119");
        kana = String
                .valueOf(String.valueOf(kana))
                .concat(
                        "\u5041\u5044\u5046\u504A\u504D\u5050\u5052\u5054\u5057\u5059\u505D\u505F\u5061\u5063\u5066\u5068\u506A\u506E\u5070\u5072\u5074\u5075\u5078\u5079\u507A\u507C\u5082\u5086\u508A\u508E\u5091\u5092\u5093\u5094\u5095\u5097\u5099\u509B\u509C\u509D\u509E\u509F\u50A0\u50A2\u50AA\u50AB");
        kana = String
                .valueOf(String.valueOf(kana))
                .concat(
                        "\u5051\u5053\u5056\u5058\u505B\u505E\u5060\u5062\u5064\u5067\u5069\u506B\u506F\u5071\u5073\u507D\u5083\u5087\u508B\u508F\u5081\u5084\u5089\u508C\u5090\u5040\u5042\u5045\u5049\u504B\u506D\u5096\u5098\u509A\u50A1\u4E55");
        kana = String
                .valueOf(String.valueOf(kana))
                .concat(
                        "\u8F88\u7092\u5200\u72AF\u8D2D\u60A3\u9A84\u5777\u8C05\u5A9A\u724C\u4FA8\u5892\u9882\u81C0\u95F2\u5CA9\u91C9\u7F69\u68D5\u4EDD\u572E\uE731\u0416\u2506\uE06C\uE0C8\uE1B5\u7519 \u4E02");
        for (int i = 0; i < str.length(); i++) {
            if (kana.indexOf(str.substring(i, i + 1)) < 0) {
                return false;
            }
        }

        return true;
    }

    /**
     * 是否有Zenkaku
     *
     * @param str
     *            源字符串
     * @return 有返回true,否则为false
     */
    public static boolean hasZenkaku(String str) {
        for (int i = 0; i < str.length(); i++) {
            String sTemp = str.substring(i, i + 1);
            byte bTmp[] = sTemp.getBytes();
            if (bTmp.length == 2) {
                return true;
            }
        }

        return false;
    }

    /**
     * 日本编码转换为ISO88591编码
     *
     * @param org
     *            源字符串
     * @return 转换后的字符串
     */
    public static String SJISToISO88591(String org) {
        if (org == null || org.equals("")) {
            return org;
        }
        try {
            byte buf[] = org.getBytes("SJIS");
            String s = new String(buf, "ISO8859_1");
            return s;
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        String s1 = null;
        return s1;
    }

    /**
     * GB编码转换为ISO88591
     *
     * @param org
     *            源字符串
     * @return 转换后的字符串
     */
    public static String GBToISO88591(String org) {
        if (org == null || org.equals("")) {
            return org;
        }
        try {
            byte buf[] = org.getBytes("GBK");
            String s = new String(buf, "ISO8859_1");
            return s;
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        String s1 = null;
        return s1;
    }

    /**
     * ISO88591编码转换为GB
     *
     * @param org
     *            源字符串
     * @return 转换后的字符串
     */
    public static String ISO88591ToGB(String org) {
        if (org == null || org.equals("")) {
            return org;
        }
        try {
            byte buf[] = org.getBytes("ISO8859_1");
            String s = new String(buf, "GBK");
            return s;
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        String s1 = null;
        return s1;
    }

    /**
     * ISO88591编码转换为GB
     *
     * @param sOrgs
     *            字符串数组
     * @return 转换后的字符串数组
     */
    public static String[] ISO88591ToGB(String sOrgs[]) {
        if (sOrgs == null) {
            return null;
        }
        for (int i = 0; i < sOrgs.length; i++) {
            sOrgs[i] = ISO88591ToGB(sOrgs[i]);

        }
        return sOrgs;
    }

    /**
     * EUC编码转换为SJIS编码
     *
     * @param org
     *            源字符串
     * @return 转换后的字符串
     */
    public static String EUCToSJIS(String org) {
        if (org == null || org.equals("")) {
            return org;
        }
        try {
            byte buf[] = org.getBytes("EUC_JP");
            String s = new String(buf, "SJIS");
            return s;
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        String s1 = null;
        return s1;
    }

    /**
     * EUC编码转换为SJIS编码
     *
     * @param sOrgs
     *            字符串数组
     * @return 转换后的字符串数组
     */
    public static String[] EUCToSJIS(String sOrgs[]) {
        if (sOrgs == null) {
            return null;
        }
        for (int i = 0; i < sOrgs.length; i++) {
            sOrgs[i] = EUCToSJIS(sOrgs[i]);

        }
        return sOrgs;
    }

    /**
     * ISO88591编码转换为SJIS编码
     *
     * @param sOrg
     *            源字符串
     * @return 转换后的字符串
     */
    public static String ISO88591ToSJIS(String sOrg) {
        return convertString(sOrg);
    }

    /**
     * ISO88591编码转换为SJIS编码
     *
     * @param sOrg
     *            源字符串数组
     * @return 转换后的字符串数组
     */
    public static String[] ISO88591ToSJIS(String sOrg[]) {
        return convertString(sOrg);
    }

    private static String convertString(String sOrg) {
        if (sOrg == null || sOrg.equals("")) {
            return null;
        }
        try {
            byte buf[] = sOrg.getBytes("ISO8859_1");
            String newStr = new String(buf, "Shift_JIS");
            String s1 = newStr;
            return s1;
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        String s = null;
        return s;
    }

    private static String[] convertString(String sOrgs[]) {
        if (sOrgs == null) {
            return null;
        }
        for (int i = 0; i < sOrgs.length; i++) {
            sOrgs[i] = convertString(sOrgs[i]);

        }
        return sOrgs;
    }

    /**
     * 判断字符串是否为数字
     *
     * @param str
     *            String 要判断的字符串
     * @return boolean 返回值,true为数字,false为非数字
     */
    public static boolean isNumber(String str) {
        for (int i = 0; i < str.length(); i++) {
            if (!Character.isDigit(str.charAt(i))) {
                return false;
            }
        }

        return true;
    }

    // 判断字符串是否有\u4FBD\u4FBE\u4FC0\u4FC1\u4FC2\u4FC6\u4FC7\u4FC8\u4FC9\u4FCB\u500E\u5010\u5011\u5013\u5015\u5016\u5017\u501B\u501D\u501E\u5020\u5022\u5023\u5024\u5027\u502B\u502F\u5030\u5031\u5032\u5033\u5034\u5035\u5036\u5037\u5038\u4FD9\u4FDB\u4FE0\u4FE2\u4FE4\u4FE5\u4FE7\u4FEB\u4FEC\u4FF0\u4FF2\u4FF4\u4FF5\u4FF6\u4FF7\u4FF9\u4FFB\u4FFC\u4FFD\u4FFF\u5000
    // \u5001\u5002\u5003\u5004\u5005其中的字样
    /**
     * 判断字符串中是否存在特定的的字符
     *
     * @param str
     *            需要检测的源字符串
     * @return 有返回true,否则为false
     */
    public static boolean containsZenNum(String str) {
        String zenNum = "\u4FBD\u4FBE\u4FC0\u4FC1\u4FC2\u4FC6\u4FC7\u4FC8\u4FC9\u4FCB";
        zenNum = String
                .valueOf(String.valueOf(zenNum))
                .concat(
                        "\u500E\u5010\u5011\u5013\u5015\u5016\u5017\u501B\u501D\u501E\u5020\u5022\u5023\u5024\u5027\u502B\u502F\u5030\u5031\u5032\u5033\u5034\u5035\u5036\u5037\u5038");
        zenNum = String
                .valueOf(String.valueOf(zenNum))
                .concat(
                        "\u4FD9\u4FDB\u4FE0\u4FE2\u4FE4\u4FE5\u4FE7\u4FEB\u4FEC\u4FF0\u4FF2\u4FF4\u4FF5\u4FF6\u4FF7\u4FF9\u4FFB\u4FFC\u4FFD\u4FFF\u5000\u5001\u5002\u5003\u5004\u5005");
        for (int i = 0; i < str.length(); i++) {
            if (zenNum.indexOf(str.substring(i, i + 1)) >= 0) {
                return true;
            }
        }

        return false;
    }

    /**
     * 处理sIn，如不为null返回原值，否则返回""
     *
     * @param sIn
     *            源字符串
     * @return 处理后的字符串
     */
    public static String nvl(String sIn) {
        return sIn != null ? sIn : "";
    }

    /**
     * 处理sIn，如不为null返回原值，否则返回sDef
     *
     * @param sIn
     *            源字符串
     * @param sDef
     *            为空返回的值
     * @return 处理后的字符串
     */
    public static String nvl(String sIn, String sDef) {
        return sIn != null ? sIn : sDef;
    }

    /**
     * 日期格式化
     *
     * @param sYear
     *            年
     * @param sMonth
     *            月
     * @param sDay
     *            日
     * @return 格式化后的日期
     */
    public static String fmtDate(String sYear, String sMonth, String sDay) {
        if (sMonth.length() == 1) {
            sMonth = "0".concat(String.valueOf(String.valueOf(sMonth)));
        }
        if (sDay.length() == 1) {
            sDay = "0".concat(String.valueOf(String.valueOf(sDay)));
        }
        return String.valueOf(String.valueOf((new StringBuffer(String
                .valueOf(String.valueOf(sYear)))).append(sMonth).append(sDay)));
    }

    /**
     * 转换日期
     *
     * @param sDate
     *            源日期字符串
     * @param sSep
     *            日期
     * @return 转换后的日期
     */
    public static String convDate(String sDate, String sSep) {
        int pos = 0;
        String str = sDate;
        int len = str.length();
        if (len < 8 || len > 10) {
            return str;
        }
        if (str.indexOf(sSep) == 4) {
            pos = str.indexOf(sSep, 5);
            if (pos == 6) {
                if (len == 8) {
                    return String.valueOf(String
                            .valueOf((new StringBuffer(String.valueOf(String
                                    .valueOf(str.substring(0, 4)))))
                                    .append("0").append(str.substring(5, 6))
                                    .append("0").append(str.substring(7, 8))));
                } else {
                    return String.valueOf(String
                            .valueOf((new StringBuffer(String.valueOf(String
                                    .valueOf(str.substring(0, 4)))))
                                    .append("0").append(str.substring(5, 6))
                                    .append(str.substring(7, 9))));
                }
            }
            if (pos == 7) {
                if (len == 9) {
                    return String.valueOf(String
                            .valueOf((new StringBuffer(String.valueOf(String
                                    .valueOf(str.substring(0, 4))))).append(
                                    str.substring(5, 7)).append("0").append(
                                    str.substring(8, 9))));
                } else {
                    return String.valueOf(String
                            .valueOf((new StringBuffer(String.valueOf(String
                                    .valueOf(str.substring(0, 4))))).append(
                                    str.substring(5, 7)).append(
                                    str.substring(8, 10))));
                }
            } else {
                return str;
            }
        } else {
            return str;
        }
    }

    /**
     * 判断字符串是否为合法日期
     *
     * @param date
     *            String 要判断的日期字符串
     * @return boolean 返回true为合法日期,false为非法日期
     */
    public static boolean chkDate(String date) {
        int months[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
        int leapdays[] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
        int days[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
        if (date == null) {
            return false;
        }
        try {
            if (date.length() == 10) {
                date = formatDate(date);
            }
            if (date.length() != 8 && date.length() != 6) {
                boolean flag = false;
                return flag;
            }
            if (date.length() == 8) {
                int year = Integer.parseInt(date.substring(0, 4));
                int month = Integer.parseInt(date.substring(4, 6));
                int day = Integer.parseInt(date.substring(6, 8));
                if (month < 1 || month > 12 || day < 1) {
                    boolean flag1 = false;
                    return flag1;
                }
                if (isLeapYear(year)) {
                    for (int i = 0; i < months.length; i++) {
                        if (months[i] == month && day > leapdays[i]) {
                            boolean flag2 = false;
                            return flag2;
                        }
                    }

                } else {
                    for (int i = 0; i < months.length; i++) {
                        if (months[i] == month && day > days[i]) {
                            boolean flag3 = false;
                            return flag3;
                        }
                    }

                }
            } else if (date.length() == 6) {
                int year = Integer.parseInt(date.substring(0, 4));
                int month = Integer.parseInt(date.substring(4, 6));
                if (month < 0 || month > 12) {
                    boolean flag4 = false;
                    return flag4;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            boolean flag5 = false;
            return flag5;
        }
        return true;
    }

    /**
     * 判断年份是否为闰年
     *
     * @param year
     *            int 要判断的年份
     * @return boolean 返回值,true为闰年,false为平年
     */
    public static boolean isLeapYear(int year) {
        if (year % 100 != 0 && year % 4 == 0) {
            return true;
        }
        return year % 400 == 0;
    }

    /**
     * 判断输入的字符串是否为合法的邮箱地址
     *
     * @param mail
     *            String 要判断的字符串
     * @return boolean 返回值,true为合法邮箱地址,flase为不合法邮箱地址
     */
    public static boolean chkMail(String mail) {
        int len = mail.length();
        int aPos = mail.indexOf("@");
        int dPos = mail.indexOf(".");
        int aaPos = mail.indexOf("@@");
        int adPos = mail.indexOf("@.");
        int ddPos = mail.indexOf("..");
        int daPos = mail.indexOf(".@");
        String lastChar = mail.substring(len - 1, len);
        String chkStr = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-_@.";
        if (aPos <= 0 || aPos == len - 1 || dPos <= 0 || dPos == len - 1
                || adPos > 0 || daPos > 0 || lastChar.equals("@")
                || lastChar.equals(".") || aaPos > 0 || ddPos > 0) {
            return false;
        }
        if (mail.indexOf("@", aPos + 1) > 0) {
            return false;
        }
        while (aPos > dPos) {
            dPos = mail.indexOf(".", dPos + 1);
            if (dPos < 0) {
                return false;
            }
        }
        for (int i = 0; i < len; i++) {
            if (chkStr.indexOf(mail.charAt(i)) < 0) {
                return false;
            }
        }

        return true;
    }

    /**
     * 清除字符串
     *
     * @param str
     *            源字符串
     * @param rc
     *            要清除的字符串
     * @return 清除后的字符串
     */
    public static String removeChar(String str, String rc) {
        if (str == null) {
            return null;
        }
        for (int i = str.indexOf(rc); i >= 0; i = str.indexOf(rc)) {
            str = String.valueOf(str.substring(0, i))
                    + String.valueOf(str.substring(i + 1, str.length()));

        }
        return str;
    }

    /**
     * 分割字符串
     *
     *
     * @param src
     *            源字符串
     * @param separator
     *            分割符
     * @return 分割后的字符串数组
     */
    public static String[] divideStr(String src, String separator) {
        if (src == null) {
            return null;
        }
        if (separator == null || separator == "") {
            String result[] = { src };
            return result;
        }
        int part = 0;
        int end = src.indexOf(separator);
        int begin;
        for (begin = end + separator.length(); end >= 0
                && begin <= src.length(); begin = end + separator.length()) {
            part++;
            end = src.indexOf(separator, begin);
        }

        String result[] = new String[part + 1];
        part = 0;
        begin = 0;
        for (end = src.indexOf(separator); end >= 0
                && end + separator.length() <= src.length(); end = src.indexOf(
                separator, ++begin)) {
            result[part++] = src.substring(begin, end);
            begin = end - 1;
            src = String.valueOf(src.substring(0, end))
                    + String.valueOf(src.substring(end + separator.length(),
                    src.length()));
        }

        result[part] = src.substring(begin, src.length());
        return result;
    }

    /**
     * 判断字符串是否合法的电话号码
     *
     * @param phone
     *            String 要判断的电话号码
     * @return boolean 返回值,true为合法电话号码,false为非法电话号码
     */
    public static boolean chkPhone(String phone) {
        int i = phone.indexOf("--");
        int len = phone.length();
        if (i >= 0) {
            return false;
        }
        i = phone.indexOf("-");
        if (i == 0 || i == len - 1) {
            return false;
        }
        if (i > 0) {
            i = phone.lastIndexOf("-");
            if (i == len - 1) {
                return false;
            }
            phone = removeChar(phone, "-");
        }
        return isNumber(phone);
    }

    /**
     * 格式化日期
     *
     * @param sDate
     *            源日期
     * @return 格式后的日期
     */
    public static String formatDate(String sDate) {
        return formatDate(sDate, null, null);
    }

    /**
     * 格式化日期
     *
     * @param sDate
     *            原日期
     * @param sFmtTo
     *            格式
     * @return 格式后的日期
     */
    public static String formatDate(String sDate, String sFmtTo) {
        return formatDate(sDate, null, sFmtTo);
    }

    /**
     * 格式化日期
     *
     * @param sDate
     *            原日期
     * @param sFmtFrom
     *            原来的格式
     * @param sFmtTo
     *            转后的格式
     * @return 格式后的日期字符串
     */
    public static String formatDate(String sDate, String sFmtFrom, String sFmtTo) {
        SimpleDateFormat sdfFrom = null;
        SimpleDateFormat sdfTo = null;
        Date dt = null;
        int nLen = 0;
        if (sDate == null) {
            return sDate;
        }
        try {
            nLen = sDate.length();
            if (sFmtFrom == null) {
                if (nLen == 8) {
                    sFmtFrom = "yyyyMMdd";
                } else if (nLen == 10) {
                    sFmtFrom = "yyyy/MM/dd";
                }
            }
            if (sFmtTo == null) {
                if (nLen == 8) {
                    sFmtTo = "yyyy/MM/dd";
                } else if (nLen == 10) {
                    sFmtTo = "yyyyMMdd";
                }
            }
            sdfFrom = new SimpleDateFormat(sFmtFrom);
            dt = sdfFrom.parse(sDate);
            sdfTo = new SimpleDateFormat(sFmtTo);
            String s = sdfTo.format(dt);
            return s;
        } catch (Exception e) {
            String s1 = sDate;
            return s1;
        }
    }

    /**
     * 比较两日期
     *
     * @param sDate1
     *            日期1
     * @param dt2
     *            日期2
     * @return 相差天数
     */
    public static int compareDate(String sDate1, Date dt2) {
        SimpleDateFormat sdf = null;
        SimpleDateFormat sdfNormalized = new SimpleDateFormat("yyyyMMdd");
        String sFmt = "";
        Date dt1 = null;
        int nLen = 0;
        if (sDate1 == null || dt2 == null) {
            return 0;
        }
        int i;
        try {
            if (sDate1.length() == 6) {
                sDate1 = String.valueOf(String.valueOf(sDate1)).concat("01");
            }
            nLen = sDate1.length();
            if (nLen == 8) {
                sFmt = "yyyyMMdd";
            } else if (nLen == 10) {
                sFmt = "yyyy/MM/dd";
            }
            sdf = new SimpleDateFormat(sFmt);
            dt1 = sdf.parse(sDate1);
            String sDt1 = sdfNormalized.format(dt1);
            String sDt2 = sdfNormalized.format(dt2);
            int j = sDt1.compareTo(sDt2);
            return j;
        } catch (Exception e) {
            i = 0;
        }
        return i;
    }

    /**
     * 比较两日期
     *
     * @param sDate1
     *            日期1
     * @param sDate2
     *            日期2
     * @return 相差天数
     */
    public static int compareDate(String sDate1, String sDate2) {
        SimpleDateFormat sdf = null;
        String sFmt = "";
        Date dt2 = null;
        int nLen = 0;
        if (sDate1 == null || sDate2 == null) {
            return 0;
        }
        try {
            if (sDate2.length() == 6) {
                sDate2 = String.valueOf(String.valueOf(sDate2)).concat("01");
            }
            nLen = sDate2.length();
            if (nLen == 8) {
                sFmt = "yyyyMMdd";
            } else if (nLen == 10) {
                sFmt = "yyyy/MM/dd";
            }
            sdf = new SimpleDateFormat(sFmt);
            dt2 = sdf.parse(sDate2);
            int i = compareDate(sDate1, dt2);
            return i;
        } catch (Exception e) {
            int j = 0;
            return j;
        }
    }

    /**
     * 判断输入的日期是否为今天
     *
     * @param sDate
     *            日期
     * @return 是今天返回true,否则为false
     */
    public static boolean isToday(String sDate) {
        return compareDate(sDate, new Date()) == 0;
    }

    /**
     * 判断输入的日期是否在今天之前
     *
     * @param sDate
     *            日期
     * @return 是返回true,否则为false
     */
    public static boolean beforeToday(String sDate) {
        return compareDate(sDate, new Date()) < 0;
    }

    /**
     * 判断输入的日期是否在今天之后
     *
     * @param sDate
     *            日期
     * @return 是返回true,否则为false
     */
    public static boolean afterToday(String sDate) {
        return compareDate(sDate, new Date()) > 0;
    }

    /**
     * 插入数据库的字符串转换
     *
     * @param sIn
     *            源字符串
     * @return 转换后的字符串
     */
    public static String toDBSelStr(String sIn) {
        if (sIn == null) {
            return sIn;
        } else {
            String sOut = sIn;
            sOut = replaceStr(sOut, "~", "~~");
            sOut = replaceStr(sOut, "%", "~%");
            sOut = replaceStr(sOut, "_", "~_");
            sOut = replaceStr(sOut, "'", "''");
            return sOut;
        }
    }

    /**
     * 插入数据库的字符串转换
     *
     * @param sIn
     *            源字符串
     * @return 转换后的字符串
     */
    public static String toDBInsStr(String sIn) {
        return toDBInsStr(sIn, -1);
    }

    /**
     * 插入数据库的字符串转换
     *
     * @param sIn
     *            源字符串
     * @param nMaxLen
     *            最大长度
     * @return 转换后的字符串
     */
    public static String toDBInsStr(String sIn, int nMaxLen) {
        if (sIn == null) {
            return sIn;
        }
        String sOut = sIn;
        sOut = replaceStr(sOut, "\"", "\u4E6D");
        if (nMaxLen != -1) {
            byte bs[] = sOut.getBytes();
            if (bs.length > nMaxLen) {
                sOut = new String(bs, 0, nMaxLen);
            }
        }
        sOut = replaceStr(sOut, "'", "''");
        return sOut;
    }

    /**
     * 转换文件为UTF8编码
     *
     * @param filename
     *            文件名
     * @return 转换后的字符串
     */
    public static String toUtf8String(String filename) {
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < filename.length(); i++) {
            char c = filename.charAt(i);
            if (c >= 0 && c <= 255) {
                if (c == ' ')
                    sb.append("%20");
                sb.append(c);
            } else {
                byte[] b;
                try {
                    b = Character.toString(c).getBytes("utf-8");
                } catch (Exception ex) {
                    System.out.println(ex);
                    b = new byte[0];
                }

                for (int j = 0; j < b.length; j++) {
                    int k = b[j];
                    if (k < 0)
                        k += 256;
                    sb.append("%" + Integer.toHexString(k).toUpperCase());
                }
            }
        }
        return sb.toString();
    }

    /**
     * 转换中文连接 URL
     *
     * @param filename
     *            文件名
     * @return 转换后的字符串
     */
    public static String URL(String filename) {
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < filename.length(); i++) {
            char c = filename.charAt(i);
            if (c >= 0 && c <= 255) {
                if (c == ' ')
                    sb.append("%20");
                else
                    sb.append(c);
            } else {

                byte[] b;
                try {
                    b = Character.toString(c).getBytes("GBK");
                } catch (Exception ex) {
                    System.out.println(ex);
                    b = new byte[0];
                }

                for (int j = 0; j < b.length; j++) {
                    int k = b[j];
                    if (k < 0)
                        k += 256;
                    sb.append("%" + Integer.toHexString(k).toUpperCase());
                }
            }
        }
        return sb.toString();
    }

    /**
     * 转换html的标签
     *
     * @param sIn
     *            源html字符串
     * @return 转换后的字符串
     */
    public static String toHTMLOutStr(String sIn) {
        if (sIn == null) {
            return sIn;
        } else {
            String sOut = sIn;
            sOut = replaceStr(sOut, "<", "&lt;");
            sOut = replaceStr(sOut, ">", "&gt;");
            sOut = replaceStr(sOut, "\n", "<BR>");
            sOut = replaceStr(sOut, " ", "&nbsp;");
            return sOut;
        }
    }

    /**
     * 判断字符是否为空格
     *
     * @param c
     *            字符
     * @return boolean 返回true 为空格,false 为非空格
     */
    public static boolean isSpaceGB(char c) {
        return c == ' ' || c == '\t' || c == '\u3000';
    }

    /**
     * 判断字符是否为空格
     *
     * @param c
     *            字符
     * @return boolean 返回true 为空格,false 为非空格
     */
    public static boolean isSpaceSJIS(char c) {
        return c == ' ' || c == '\t' || c == '\u4E02';
    }

    /**
     * 判断字符是否为空格
     *
     * @param c
     *            字符
     * @return boolean 返回true 为空格,false 为非空格
     */
    public static boolean isSpace(char c) {
        return isSpaceGB(c);
    }

    /**
     * 判断字符串中是否以空格开头
     *
     * @param s
     *            要判断的字符串
     * @return boolean 返回值,true为以空格开头,false为非空格开头
     */
    public static boolean isSpace(String s) {
        if (s == null) {
            return false;
        }
        for (int i = 0; i < s.length(); i++) {
            if (!isSpace(s.charAt(i))) {
                return false;
            }
        }

        return true;
    }

    /**
     * 判断字符串中是否以空格开头
     *
     * @param s
     *            要判断的字符串
     * @return boolean 返回值,true为以空格开头,false为非空格开头
     */
    public static boolean isSpaceSJIS(String s) {
        if (s == null) {
            return false;
        }
        for (int i = 0; i < s.length(); i++) {
            if (!isSpaceSJIS(s.charAt(i))) {
                return false;
            }
        }

        return true;
    }

    /**
     * 过滤字符
     *
     * @param value
     *            源字符串
     * @return 过滤后的字符串
     */
    public static String filter(String value) {
        if (value == null) {
            return null;
        }
        StringBuffer result = new StringBuffer();
        for (int i = 0; i < value.length(); i++) {
            char ch = value.charAt(i);
            if (ch == '<') {
                result.append("&lt;");
                continue;
            }
            if (ch == '>') {
                result.append("&gt;");
                continue;
            }
            if (ch == '&') {
                result.append("&amp;");
                continue;
            }
            if (ch == '"') {
                result.append("&quot;");
                continue;
            }
            if (ch == '\r') {
                result.append("<BR>");
                continue;
            }
            if (ch == '\n') {
                if (i <= 0 || value.charAt(i - 1) != '\r') {
                    result.append("<BR>");
                }
                continue;
            }
            if (ch == '\t') {
                result.append("&nbsp;&nbsp;&nbsp;&nbsp");
                continue;
            }
            if (ch == ' ') {
                result.append("&nbsp;");
            } else {
                result.append(ch);
            }
        }

        return result.toString();
    }

    /**
     * 用\r\n填充content的长度小于splitLen的大小的空间
     *
     * @param content
     *            源字符串
     * @param splitLen
     *            长度
     * @return 转换后的字符串
     */
    public static String doInsertCR(String content, int splitLen) {
        if (content == null) {
            return null;
        }
        int bytePos = 0;
        StringBuffer result = new StringBuffer();
        for (int i = 0; i < content.length(); i++) {
            if (content.substring(i, i + 1).getBytes().length == 2) {
                bytePos += 2;
            } else {
                bytePos++;
            }
            result.append(content.substring(i, i + 1));
            if (content.substring(i, i + 1).equalsIgnoreCase("\n")) {
                bytePos = 0;
                continue;
            }
            if (bytePos >= splitLen) {
                result.append("\r\n");
                bytePos = 0;
            }
        }

        String retString = new String(result);
        return retString;
    }

    /**
     * 过滤字符串
     *
     * @param value
     *            源字符串
     * @return 过滤后的字符串
     *
     */
    public static String filter2(String value) {
        if (value == null) {
            return null;
        }
        StringBuffer result = new StringBuffer();
        for (int i = 0; i < value.length(); i++) {
            char ch = value.charAt(i);
            if (ch == '<') {
                result.append("&lt;");
                continue;
            }
            if (ch == '>') {
                result.append("&gt;");
                continue;
            }
            if (ch == '&') {
                result.append("&amp;");
                continue;
            }
            if (ch == '"') {
                result.append("&quot;");
                continue;
            }
            if (ch == '\r') {
                result.append("<BR>");
                continue;
            }
            if (ch == '\t') {
                result.append("&nbsp;&nbsp;&nbsp;&nbsp");
            } else {
                result.append(ch);
            }
        }

        return result.toString();
    }

    /**
     * 比较两字符串
     *
     * @param source
     *            源字符串
     * @param dest
     *            目标字符串
     * @return 返回比较后的值
     */
    public static int compareString(String source, String dest) {
        boolean rst = false;
        String newsource = StringUtil.sortByAsc(StringUtil.delSpace(source));
        String newdest = StringUtil.sortByAsc(StringUtil.delSpace(dest));
        return newsource.compareTo(newdest);
    }

    /**
     * 比较字符串
     *
     * @param source
     *            源字符串
     * @param dest
     *            目标字符串
     * @param returnstr
     *            返回字符
     * @return 返回比较后的值
     */
    public static String compareString(String source, String dest,
                                       String returnstr) {
        if (source != null && source.equalsIgnoreCase(dest))
            return returnstr;
        else
            return "";
    }

    /**
     * 比较字符串,忽略大小写
     *
     * @param source
     *            源字符串
     * @param dest
     *            目标字符串
     * @return 返回比较后的值
     */
    public static int compareStringIgnoreCase(String source, String dest) {
        boolean rst = false;
        String newsource = StringUtil.sortByAsc(StringUtil.delSpace(source))
                .toLowerCase();
        String newdest = StringUtil.sortByAsc(StringUtil.delSpace(dest))
                .toLowerCase();
        return newsource.compareTo(newdest);
    }

    /**
     * 删除字符串中的空格
     *
     * @param source
     *            源字符串
     * @return 删除字符串
     */
    public static String delSpace(String source) {
        String rst = "";
        if (source == null)
            return null;
        for (int i = 0; i < source.length(); i++) {
            if (source.charAt(i) != ' ')
                rst += source.charAt(i);
        }
        return rst;
    }

    /**
     * 升序排序字符串
     *
     * @param sourcestr
     *            排序字符串
     * @return 排序后的字符串
     */
    public static String sortByAsc(String sourcestr) {
        String rst = "";
        byte source[] = sourcestr.getBytes();
        for (int i = 0; i < source.length; i++) {
            for (int j = i + 1; j < source.length; j++) {
                byte c;
                if (source[i] > source[j]) {
                    c = source[i];
                    source[i] = source[j];
                    source[j] = c;
                }
            }
        }
        rst = new String(source);
        return rst;
    }

    /**
     * 处理字符串
     *
     * @param s
     *            源字符串
     * @return 如果为空，则返回&nbsp;,否则为s
     */
    public static String chargeNull(String s) {
        if (s != null && s.length() > 0)
            return s;
        else
            return "&nbsp;";
    }

    /**
     * 处理字符串的<div>和</div>
     *
     * @param s
     *            源字符串
     * @return 如果为null则返回s,否则返回清除<div>和</div>后的字符串
     */
    public static String chargeDIV(String s) {
        String s1 = s;
        if (s1 == null)
            return s1;
        else {
            if (s1.startsWith("<DIV>"))
                s1 = s1.substring(5);
            if (s1.endsWith("</DIV>"))
                s1 = s1.substring(0, s1.length() - 6);
        }
        return s1;
    }

    /**
     * 截取字符串
     *
     * @param s
     *            源字符串
     * @param length
     *            截取长度
     * @return 截取后的字符串
     */
    public static String cutString(String s, int length) {
        if (s.length() > length)
            return s.substring(0, length);
        else
            return s;
    }

    /**
     * 对链接处理中显示的字符串作截取处理
     *
     * @param s
     *            字符串
     * @param length
     *            长度
     * @param href
     *            链接
     * @return 处理后的样式
     */
    public static String hrefString(String s, int length, String href) {
        return hrefString(s, length, href, "");
    }

    /**
     * 对链接处理太长的字符串显示问题
     *
     * @param s
     *            字符串
     * @param length
     *            长度
     * @param href
     *            链接
     * @param style
     *            样式
     * @return 处理后的样式
     */
    public static String hrefString(String s, int length, String href,
                                    String style) {
        String rst = "";
        if (s.length() > length) {
            rst = "<a href=\"" + href + "\" title=\"" + s + "\" " + style + ">"
                    + cutString(s, length, "...") + "</a>";
        } else {
            rst = "<a href=\"" + href + "\" " + style + ">" + s + "...</a>";
        }
        return rst;
    }

    /**
     * 截取字符串
     *
     * @param s
     *            源字符串
     * @param length
     *            长度
     * @param dotstr
     *            附加字符串
     * @return 截取并合并的字符串
     */
    public static String cutString(String s, int length, String dotstr) {
        return left(s, length, dotstr);
    }

    /**
     * 去除字符串首尾空格
     *
     * @param s
     *            源字符串
     * @return 处理后的字符串
     */
    public static String trim(String s) {
        if (s == null) {
            return null;
        }
        int begin;
        for (begin = 0; begin < s.length() && isSpace(s.charAt(begin)); begin++) {
            ;
        }
        int end;
        for (end = s.length() - 1; end >= 0 && isSpace(s.charAt(end)); end--) {
            ;
        }
        if (end < begin) {
            return "";
        } else {
            return s.substring(begin, end + 1);
        }
    }

    /**
     * 分割字符串
     *
     * @param str
     *            源字符串
     * @param x
     *            分割符
     * @return 分割后的字符串数组
     */
    public static String[] split(String str, char x) {
        ArrayList ar = new ArrayList();
        String str1 = new String();
        for (int i = 0; i < str.length(); i++) {
            if (str.charAt(i) == x) {
                ar.add(str1);
                str1 = new String();
            } else
                str1 = String.valueOf(str1) + String.valueOf(str.charAt(i));
        }
        ar.add(str1);
        String array[] = new String[ar.size()];
        for (int i = 0; i < array.length; i++)
            array[i] = new String((String) ar.get(i));
        return array;
    }

    /**
     * 分割字符串
     *
     * @param str
     *            源字符串
     * @param str1
     *            分割符
     * @return 分割后的字符串数组
     */
    public static String[] split(String str, String str1) {
        ArrayList ar = new ArrayList();
        String str2 = str;
        int intPos = 0;
        int str2length = str1.length();
        while ((intPos = str2.indexOf(str1)) != -1) {
            String str3 = str2.substring(0, intPos);
            ar.add(str3);
            str2 = str2.substring(intPos + str2length);
        }
        ar.add(str2);
        String array[] = new String[ar.size()];
        for (int i = 0; i < array.length; i++)
            array[i] = new String((String) ar.get(i));
        return array;
    }

    /**
     * 长数字字符串转长整型
     *
     * @param input
     *            数字字符串
     * @return 转换后的长整型
     */
    public static long unFormatNum(String input) {
        if (input == null || input.equals("")) {
            return 0L;
        }
        String tmp = removeChar(input, ",");
        if (isNumber(tmp)) {
            long output;
            try {
                output = Long.parseLong(tmp);
            } catch (Exception e) {
                long l = -1L;
                return l;
            }
            return output;
        } else {
            return -1L;
        }
    }

    /**
     * 数字转字符串
     *
     * @param input
     *            数字
     * @return 字符串
     */
    public static String formatNum(int input) {
        if (input < 0) {
            return "";
        }
        String tmp = String.valueOf(input);
        String output = "";
        int len = tmp.length();
        int i = len;
        do {
            if (i <= 0) {
                break;
            }
            if (i < 3) {
                output = String.valueOf(tmp.substring(0, i))
                        + String.valueOf(output);
                break;
            }
            i -= 3;
            output = String.valueOf(tmp.substring(i, i + 3))
                    + String.valueOf(output);
            if (i > 0) {
                output = ",".concat(String.valueOf(String.valueOf(output)));
            }
        } while (true);
        return output;
    }

    /**
     * 长整型转字型串
     *
     * @param input
     *            长整型
     * @return 字型串
     */
    public static String formatNum(long input) {
        if (input < (long) 0) {
            return "";
        }
        String tmp = String.valueOf(input);
        String output = "";
        int len = tmp.length();
        int i = len;
        do {
            if (i <= 0) {
                break;
            }
            if (i < 3) {
                output = String.valueOf(tmp.substring(0, i))
                        + String.valueOf(output);
                break;
            }
            i -= 3;
            output = String.valueOf(tmp.substring(i, i + 3))
                    + String.valueOf(output);
            if (i > 0) {
                output = ",".concat(String.valueOf(String.valueOf(output)));
            }
        } while (true);
        return output;
    }

    /**
     * 数字型字符串转字符串
     *
     * @param input
     *            数字型字符串
     * @return 字符串
     */
    public static String formatNum(String input) {
        if (input == null) {
            return null;
        }
        if (input.trim().length() == 0) {
            return null;
        }
        String tmp = input;
        String output = "";
        int len = tmp.length();
        int i = len;
        do {
            if (i <= 0) {
                break;
            }
            if (i < 3) {
                output = String.valueOf(tmp.substring(0, i))
                        + String.valueOf(output);
                break;
            }
            i -= 3;
            output = String.valueOf(tmp.substring(i, i + 3))
                    + String.valueOf(output);
            if (i > 0) {
                output = ",".concat(String.valueOf(String.valueOf(output)));
            }
        } while (true);
        return output;
    }

    /**
     * 返回字符串长度
     *
     * @param str
     *            源字符串
     * @return 长度
     */
    public static int length(String str) {
        if (str == null) {
            return 0;
        } else {
            return str.getBytes().length;
        }
    }

    /**
     * 取字符左边的第N个子符，一个中文按两个字符计算
     *
     * @param s
     *            字符
     * @param offset
     *            截取字符长度
     * @return 截取后的字符
     */
    public static String left(String s, int offset) {
        return left(s, offset);
    }

    /**
     * 取字符左边的第N个子符，一个中文按两个字符计算
     *
     * @param s
     *            字符
     * @param offset
     *            截取字符长度
     * @param addStr
     *            附加字符
     * @return 截取后的字符
     */
    public static String left(String s, int offset, String addStr) {
        char[] cs = s.toCharArray();
        int count = 0;
        int last = cs.length;
        for (int i = 0; i < cs.length; i++) {
            if (cs[i] > 255)
                count += 2;
            else
                count++;
            if (count > offset) {
                last = i + 1;
                break;
            }
        }
        if (count <= offset) // string is short or just the size!
            return s;
        // string is too long:
        offset -= addStr.length();
        for (int i = last - 1; i >= 0; i--) {
            if (cs[i] > 255)
                count -= 2;
            else
                count--;
            if (count <= offset) {
                return s.substring(0, i) + addStr;
            }
        }
        return addStr;
    }

    /**
     * BIG5编码转ISO88591编码
     *
     * @param org
     *            源字符串
     * @return 转换后的字符串
     */
    public static String BIG5ToISO88591(String org) {
        if (org == null || org.equals("")) {
            return org;
        }
        try {
            byte buf[] = org.getBytes("BIG5");
            String s = new String(buf, "ISO8859_1");
            return s;
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        String s1 = null;
        return s1;
    }

    /**
     * ISO88591编码转BIG5编码
     *
     * @param org
     *            源字符串
     * @return 转换后的字符串
     */
    public static String ISO88591ToBIG5(String org) {
        if (org == null || org.equals("")) {
            return org;
        }
        try {
            byte buf[] = org.getBytes("ISO8859_1");
            String s = new String(buf, "BIG5");
            return s;
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        String s1 = null;
        return s1;
    }

    /**
     * ISO88591编码转BIG5编码
     *
     * @param sOrgs
     *            源字符串数组
     * @return 转换后的字符串数组
     */
    public static String[] ISO88591ToBIG5(String sOrgs[]) {
        if (sOrgs == null) {
            return null;
        }
        for (int i = 0; i < sOrgs.length; i++) {
            sOrgs[i] = ISO88591ToBIG5(sOrgs[i]);

        }
        return sOrgs;
    }

    /**
     * 字符串Vbscript
     *
     * @param tempString
     *            源字符串
     * @return 转换后的字符串数组
     */
    public static String charToVbscript(String tempString) {
        String returnString = replaceStr(tempString, "\r\n", "\"+vbcrlf+\"");
        returnString = replaceStr(returnString, "\r", "\"+vbcrlf+\"");
        returnString = replaceStr(returnString, "\n", "\"+vbcrlf+\"");
        return returnString;
    }

    /**
     * 截取掉尾字符串deststr
     *
     * @param sourcestr
     *            源字符串
     * @param deststr
     *            目标字符串
     * @return 转换后的字符串
     */
    public static String getTailString(String sourcestr, String deststr) {
        String curstr = "";
        int i = sourcestr.lastIndexOf(deststr);
        if (i > 0 && i < sourcestr.length())
            curstr = sourcestr.substring(i + 1);
        return curstr;
    }

    /**
     * 截取掉头字符串deststr
     *
     * @param sourcestr
     *            源字符串
     * @param deststr
     *            目标字符串
     * @return 转换后的字符串
     */
    public static String getHeadString(String sourcestr, String deststr) {
        String curstr = "";
        int i = sourcestr.lastIndexOf(deststr);
        if (i > 0 && i < sourcestr.length())
            curstr = sourcestr.substring(0, i);
        else
            curstr = sourcestr;
        return curstr;
    }

    /**
     * 截取掉头字符串deststr
     *
     * @param sourcestr
     *            源字符串
     * @param deststr
     *            目标字符串
     * @return 转换后的字符串
     */
    public static String getHeadStringWithOwn(String sourcestr, String deststr) {
        String curstr = "";
        int i = sourcestr.lastIndexOf(deststr);
        if (i > 0 && i < sourcestr.length())
            curstr = sourcestr.substring(0, i + 1);
        else
            curstr = sourcestr;
        return curstr;
    }

    /**
     * 将字符串首字母大写
     *
     * @param source
     *            源字符串
     * @return 转换后的字符串
     */
    public static String getToUpperFisrtChar(String source) {
        String rst = "";
        if (source == null || source.length() == 0)
            return source;
        else
            return source.substring(0, 1).toUpperCase() + source.substring(1);
    }




    public static void main(String argv[]) {
        try {
            // String curNo = "广州本田内部网统一帐号 管理方案 v1 . 0.doc?11222";
            // System.out.println(StringUtil.URL(curNo));
            // System.out.println(java.net.URLEncoder.encode(curNo, "GBK"));
            // System.out.println(new String(curNo.getBytes("GBK"), "UTF-8"));
            System.out.println(unFormatNum("asasadasa"));
        } catch (Exception E) {
            E.printStackTrace();
        }
    }
}